package com.fdb.efp.nls.service.impl.yed.queue;

import com.fdb.efp.nls.service.impl.yed.compensate.CompensationYedTask;
import com.google.common.collect.Maps;
import com.fdb.basic.framework.core.threadpool.AbstractThreadTask;
import com.fdb.basic.framework.core.threadpool.ExecuteRtnInfo;
import com.fdb.basic.framework.core.util.SpringContextUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 需求编号：【2019D0509】（业务提的需求编号）
 * 问题编号：【】（若不是因为修复问题而新增该类，则留空）
 * 开发人员：【wanglh4】
 * 创建日期：【2020/7/28 15:01】
 * 功能描述：
 */
@Service("yedReleaseOrRepayQueueHangHandleService")
@Scope(scopeName = "prototype")
public class YedReleaseOrRepayQueueHangHandle extends AbstractThreadTask {

    public static final String  NLSAPPLYINFOVO = "NlsApplyInfoVO-";
    public static final String  LOANREPAYDETAILVO = "LoanRepayDetailVO-";

    private Logger logger = LoggerFactory.getLogger(YedReleaseOrRepayQueueHangHandle.class);
    private String key;
    private String body;

    // 类型映射
    public static final Map<String, String> serviceMap = Maps.newHashMap();
    static {
        serviceMap.put("NlsApplyInfoVO","loanReleaseCompensationYedTask");
        serviceMap.put("LoanRepayDetailVO","repayCompensationYedTask");
    }
    @Override
    public ExecuteRtnInfo call() throws Exception {
        this.doTask();
        return new ExecuteRtnInfo(null, null, null, null, true);
    }

    @Override
    public void doTask() {
        // 找出对应需要执行的服务
        for (String keyService : serviceMap.keySet()) {
            if (key.contains(keyService)) {
                try {
                    CompensationYedTask updateService
                            = SpringContextUtils.getBean(serviceMap.get(keyService), CompensationYedTask.class);
                    updateService.parseTAndUpdateStatus(body);
                } catch (Exception e) {
                    logger.error("【放款还款更新服务执行失败】"+e);
                    e.printStackTrace();
                }
                return;
            }
        }
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }
}
